package com.devframe.component.ftlprocess;



import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.devframe.component.ftlprocess.freemarker.context.MyFTLProcessHandleContext;
/**
 * 
 * @author 詹保山(softzbs@126.com)
 * @desc: 获取上下文信息的类
 * Jul 9, 2010
 */
public class MyFTLProcessContextContainer implements ApplicationContextAware{
	private static Logger logger = Logger.getLogger(MyFTLProcessContextContainer.class);
	private static ContextHelper helper = new ContextHelper();
	private static MyFTLProcessContextContainer instance;
	private ApplicationContext appContext;
	
	private  MyFTLProcessHandleContext handleContext;
	
	private MyFTLProcessContextContainer() {}
	
	private static class ContextHelper  {
		public Object getBean(String beanName) {
			return MyFTLProcessContextContainer.instance.appContext.getBean(beanName);
		}
		public MyFTLProcessHandleContext getHandleContext(){
			return MyFTLProcessContextContainer.instance.handleContext;
		}
		
	}
	private static MyFTLProcessContextContainer factoryMethod() {
		logger.info("初始化MyReport上下文");
		instance = new MyFTLProcessContextContainer();
		return instance;
	}
	/**
	 * 
	 * Aug 28, 2011<br/>
	 * @描述：获取当前实例
	 * <br/> 
	 * @return
	 */
	public static MyFTLProcessContextContainer getInstance(){
		return MyFTLProcessContextContainer.instance;
	}
 
	/**
	 * 根据BeanName的名称获得 BEAN实体
	 * @param beanName bean的名称
	 * @return 
	 * @author:詹保山softzbs@126.com
	 */
	public  Object getSpringBean(String beanName) {
		return helper.getBean(beanName);
	}
	/**
	 * 判断Bean在Spring 容器中
	 * @param beanName
	 * @return
	 * @author:詹保山
	 */
	public boolean containsSpringBean(String beanName){
		return MyFTLProcessContextContainer.instance.appContext.containsBean(beanName);
	}
 
 
	private void initMyReportContext(){
		
//		templatePath=this.servletContext.getRealPath(templatePath);
		
		
		logger.info("初始化模板解析器的上下文");
//		MyReportHandleManager.initTemplate();
//		this.handleContext=new MyFTLProcessHandleContext();
		
	}
 
	public MyFTLProcessHandleContext getHandleContext() {
		return handleContext;
	}
	public void setHandleContext(MyFTLProcessHandleContext handleContext) {
		this.handleContext = handleContext;
	}
	public void setApplicationContext(ApplicationContext appContext){
		this.appContext=appContext;
		initMyReportContext();
	}

 
}
